package com.yw.atp.action;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.yw.atp.model.Meeting;
import com.yw.atp.service.PersistenceService;
import com.yw.atp.web.ActionBase;

@Scope("prototype")
@Component("meetingAction")
public class MeetingAction extends ActionBase implements ServletRequestAware{
	private static final long serialVersionUID = 1L;
	@Autowired
	private PersistenceService service;
	HttpServletRequest request;
	public Meeting info;
	public Meeting getInfo() {
		return info;
	}

	public void setInfo(Meeting info) {
		this.info = info;
	}

	public String ids;
	
	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public PersistenceService getService() {
		return service;
	}

	public void setService(PersistenceService service) {
		this.service = service;
	}

	public String add(){
		service.save(info);
		return SUCCESS;
	}
	
	public String edit(){
		if(service.isExsist(Meeting.class.getName(),info.getId())){
			service.save(info);
		}
		return SUCCESS;
	}
	
	public String del(){
		service.del(Meeting.class.getName(),ids);
		return SUCCESS;
	}
	
	public void setServletRequest(HttpServletRequest request) {
        if(request==null){
            request = ServletActionContext.getRequest();
        }
        this.request = request;
    }
	
}
